package com.lei.leetcode;

import java.util.LinkedList;

/**
 * @Author LeiXiaoLei
 * @Date 2022/8/17 21:13
 * @Version 1.0
 */
public class S_1302 {
    public static void main(String[] args) {
        System.out.println(Math.pow(2, 0) == 1);
    }

    public int deepestLeavesSum(TreeNode root) {
        int res = 0;
        if (root == null) return res;
        LinkedList<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        while (!queue.isEmpty()) {
            res = 0;
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode cur = queue.pop();
                res += cur.val;
                if (cur.left != null) queue.add(cur.left);
                if (cur.right != null) queue.add(cur.right);
            }
        }
        return res;
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
